package com.zhentao.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;

/**
 * @author 王瑞杰
 * date 2024/5/9
 */
@EnableConfigurationProperties(WxMaServiceConfigProperties.class)
public class WxMaServiceConfig {
    @Resource
    private WxMaServiceConfigProperties wxMaServiceConfigProperties;
    @Bean
    private WxMaService getWxMaService() {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(wxMaServiceConfigProperties.getAppid());
        config.setSecret(wxMaServiceConfigProperties.getSecret());
        config.setMsgDataFormat("JSON");
        cn.binarywang.wx.miniapp.api.WxMaService wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(config);
        return wxMaService;
    }
}
